package shop.web.controller.front.organize;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.services.front.area.AreaService;
import shop.services.front.area.bean.Area;
import shop.services.front.offline.OfflineService;
import shop.services.front.offline.bean.Offline;
import shop.services.front.offlineAccount.OfflineAccountService;
import shop.services.front.offlineAccount.bean.OfflineAccount;
import shop.services.front.organize.OrganizeService;
import shop.services.front.organize.bean.Organize;
import shop.services.front.organizeAccount.OrganizeAccountService;
import shop.services.front.organizeAccount.bean.OrganizeAccount;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/4/17.
 */
@Controller
@RequestMapping("/organize")
public class OrganizeController extends FrontBaseController<Organize> {
    @Resource
    private AreaService areaService;
    @Resource
    private OfflineService offlineService;
    @Resource
    private OfflineAccountService offlineAccountService;
    @Resource
    private OrganizeService organizeService;
    @Resource
    private OrganizeAccountService organizeAccountService;

    @Override
    public Services<Organize> getService() {
        return organizeService;
    }


    /**
     * 页面跳转方法
     *
     * @return
     */
    @RequestMapping("/toOrganizeList")
    public String toOrganizeList() {
        return "/front/organize/organizeList";
    }

    @RequestMapping("/toOrganizeDetail")
    public String toOrganizeDetail() {
        return "/front/organize/organizedetail";
    }

    @RequestMapping("/toOrganizeJoin")
    public String toOrganizeJoin() {
        return "/front/organize/organizeJoin";
    }

    @RequestMapping("/toOfflineDetail")
    public String toOfflineDetail() {
        return "/front/organize/offlineDetail";
    }

    @RequestMapping("/toOfflineJoin")
    public String toOfflineJoin() {
        return "/front/organize/offlineJoin";
    }

    /**
     * 查询地级市
     *
     * @param area
     * @return
     */
    @RequestMapping(value = "/selectArea",  method = RequestMethod.GET)
    @ResponseBody
    public JSONResult selectArea(Area area) {
        JSONResult jsonResult = new  JSONResult();
        List<Area> list = areaService.selectList(area);
        jsonResult.setData(list);
        jsonResult.setSuccess(true);
        return jsonResult;
    }

    /**
     * 查询全部活动(机构详情页面活动信息)
     *
     * @param offline
     * @return
     */
    @RequestMapping(value = "/selectOffline", method = RequestMethod.GET)
    @ResponseBody
    public JSONResult selectOffline(Offline offline) {
        JSONResult jsonResult = new JSONResult();
        List<Offline> list = offlineService.selectList(offline);
        jsonResult.setData(list);
        jsonResult.setSuccess(true);
        return jsonResult;
    }

    /**
     * 查询单个活动
     *
     * @param offline
     * @return
     */
    @RequestMapping(value = "/selectOfflineDetail", method = RequestMethod.GET)
    @ResponseBody
    public JSONResult selectOfflineDetail(Offline offline) {
        jsonResult = new JSONResult();
        Offline rs = offlineService.selectOne(offline);
        jsonResult.setData(rs);
        jsonResult.setSuccess(true);
        return jsonResult;
    }

    /**
     * 加入活动方法
     *
     * @return jsonResult
     * @throws Exception
     */
    @RequestMapping(value = "/insertOfflineAccount", method = RequestMethod.POST)
    @ResponseBody
    public JSONResult insertOfflineAccount(OfflineAccount offlineAccount) throws Exception {
        JSONResult jsonResult = new JSONResult();
        offlineAccountService.insert(offlineAccount);
        jsonResult.setSuccess(true);
        return jsonResult;
    }

    /**
     * 加入机构方法
     *
     * @return jsonResult
     * @throws Exception
     */
    @RequestMapping(value = "/insertOrganizeAccount", method = RequestMethod.POST)
    @ResponseBody
    public JSONResult insertOrganizeAccount(OrganizeAccount organizeAccount) throws Exception {
        JSONResult jsonResult = new JSONResult();
        organizeAccountService.insert(organizeAccount);
        jsonResult.setSuccess(true);
        return jsonResult;
    }

    /**
     * 机构详情页面会员信息
     *
     * @param organizeAccount
     * @return
     */
    @RequestMapping(value = "/selectOrganizeAccount", method = RequestMethod.GET)
    @ResponseBody
    public JSONResult selectOrganizeAccount(OrganizeAccount organizeAccount) {
        JSONResult jsonResult = new JSONResult();
        List<OrganizeAccount> list = organizeAccountService.selectList(organizeAccount);
        jsonResult.setData(list);
        jsonResult.setSuccess(true);
        return jsonResult;
    }

    /**
     * 根据用户查活动
     * @param offlineAccount 用户活动
     * @return 用户活动列表
     */
    @RequestMapping(value = "/selectOfflineList",method = RequestMethod.GET)
    @ResponseBody
    public JSONResult selectOfflineList(OfflineAccount offlineAccount){
        JSONResult rs=new JSONResult();
        rs.setData(offlineAccountService.selectListByAccount(offlineAccount));
        rs.setSuccess(true);
        return rs;
    }

    /**
     * 根据用户查询机构
     * @param OrganizeAccount 用户机构
     * @return 用户机构列表
     */
    @RequestMapping(value = "/selectOrganizeList",method = RequestMethod.GET)
    @ResponseBody
    public  JSONResult selectOrganizeList(OrganizeAccount OrganizeAccount){
        JSONResult rs=new JSONResult();
        rs.setData(organizeAccountService.selectListByAccount(OrganizeAccount));
        rs.setSuccess(true);
        return rs;
    }
}